$(document).ready(function(){    
    $('#id-check').click(function(){
        var uname = $('#name').val();
        var imglink = '<img src=\'Images/fail.png\' width=\'14\' alt=\'fail\'/><span class=\'fail\'>Tên đăng nhập quá ngắn.</span>';
        var datastring = 'name='+ uname;
        $('#id-checked').empty();
        if(uname.length >= 4){
            $.ajax({
                type: 'GET',
                url: './SourceCode/dangky_check.php',
                data: datastring,
                success: function(server_response) {
                 $('#id-checked').html(server_response);   
                }
            });
        }else{
            $('#id-checked').html(imglink);
        }
    });
    $('#pass-check').click(function(){
        var upass = $('#pass1').val();
        var datastring = 'pass=' + upass;
        $('#pass-checked').empty();
        if(upass.length >= 5){
            $.ajax({
                type: 'GET',
                url: "./SourceCode/dangky_check.php",
                data: datastring,
                success: function(server_response) {
                    $('#pass-checked').html(server_response);
                }
            });
        }else{
            $('#pass-checked').html('<img src=\'Images/fail.png\' width=\'14\' alt=\'fail\'/><span class=\'fail\'>Mật khẩu quá ngắn.</span>');
        }
    });
    $('#email-check').click(function(){
        var uemail = $('#email').val();
        var datastring = 'email=' + uemail;
        $('#email-checked').empty();
        if(uemail.length>=4){
            $.ajax({
                type: 'GET',
                url: "./SourceCode/dangky_check.php",
                data: datastring,
                success: function(server_response) {
                    $('#email-checked').html(server_response);
                }
            });
        }else{
            $('#email-checked').html('<img src=\'Images/fail.png\' width=\'14\' alt=\'fail\'/><span class=\'fail\'>Email quá ngắn.</span>');
        }
    });
    
    $('#roomname-check').click(function(){
        var rname = $('#roomname').val();
        var datastring = 'rname=' + rname;
        $('#roomname-checked').empty();
        if(rname.length>=2){
            $.ajax({
                type: 'GET',
                url: "./SourceCode/dangky_check.php",
                data: datastring,
                success: function(server_response) {
                    $('#roomname-checked').html(server_response);
                }
            });
        }else{
            $('#roomname-checked').html('<img src=\'Images/fail.png\' width=\'14\' alt=\'fail\'/><span class=\'fail\'>Tên phòng quá ngắn.</span>');
        }
    });
});